package exam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import exam.bean.Student;
import exam.dao.StudentDao;
import exam.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements IStudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public int insertInfo(Student student) {
        return studentDao.insertInfo(student);
    }

    @Override
    public int deleteInfo(int id) {
        return studentDao.deleteInfo(id);
    }

    @Override
    public int updateInfo(Student student) {
        return studentDao.updateInfo(student);
    }

    @Override
    public PageInfo<Student> selectInfo(int pageNum, int pageSize,Map<String,Object> queryMap) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> studentList = studentDao.selectInfo(queryMap);
        PageInfo<Student> pageInfo = new PageInfo<>(studentList);
        return pageInfo;
    }

    @Override
    public Student selectInfoSingle(Map<String,Object> map) {
        return studentDao.selectInfo(map).get(0);
    }
}
